import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nyh_motorcade_app/constant/constant.dart';
import 'package:nyh_motorcade_app/entity/driver_info_entity.dart';
import 'package:nyh_motorcade_app/routes/routes.dart';
import 'package:nyh_motorcade_app/styles/colors.dart';
import 'package:nyh_motorcade_app/utils/format_utils.dart';
import 'package:nyh_motorcade_app/widgets/flexible_icon_text.dart';
import 'package:nyh_motorcade_app/widgets/highlight_rich_text.dart';
import 'package:nyh_motorcade_app/widgets/text_with_icon.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class DriverItem extends StatelessWidget {
  final DriverInfoItem entity;
  final String? keyword;
  final FocusNode? focusNode;

  DriverItem(this.entity, {this.keyword, this.focusNode});

  @override
  Widget build(BuildContext context) {
    List<String> quotaList = [];
    if (entity.refuelQuota != null) {
      quotaList.add("限额：${FormatUtils.formatMoney(entity.refuelQuota)}${entity.unit ?? ""}/${entity.circle ?? ""}");
    }
    if (entity.remainQuota != null) {
      quotaList.add("剩余：${FormatUtils.formatMoney(entity.remainQuota)}${entity.unit ?? ""}/${entity.circle ?? ""}");
    }
    return Container(
      margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 12.w),
      decoration: BoxDecoration(
        color: Colours.color_white,
        borderRadius: BorderRadius.circular(10.w),
      ),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(10.w),
        child: Material(
          child: InkWell(
            onTap: () {
              if (focusNode != null) {
                focusNode!.unfocus();
              }
              Get.toNamed(Routes.driverDetails, arguments: entity.id);
            },
            child: Padding(
              padding: EdgeInsets.symmetric(vertical: 13.w, horizontal: 16.w),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Flexible(
                        child: HighlightRichText(
                          text: entity.name ?? "",
                          highlightList: [keyword ?? ""],
                          highlightStyle: TextStyle(
                            color: Colours.color_theme,
                            fontSize: 16.sp,
                            fontWeight: FontWeight.bold,
                          ),
                          normalStyle: TextStyle(
                            color: Colours.color_text_theme,
                            fontSize: 16.sp,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                      Visibility(
                        visible: (entity.belongingType ?? "").isNotEmpty,
                        child: Container(
                          margin: EdgeInsets.only(left: 8.w),
                          padding: EdgeInsets.only(left: 5.w, right: 5.w, bottom: 1.w),
                          decoration: BoxDecoration(
                            color: (entity.belongingType ?? "") == Constant.OWN_DRIVER ? Colours.color_34c759 : Colours.color_theme,
                            borderRadius: BorderRadius.circular(5.w),
                            border: Border.all(width: 1.w, color: (entity.belongingType ?? "") == Constant.OWN_DRIVER ? Colours.color_34c759 : Colours.color_theme),
                          ),
                          child: Text(
                            entity.belongingTypeName ?? "",
                            style: TextStyle(
                              color: Colours.color_white,
                              fontSize: 10.sp,
                            ),
                          ),
                        ),
                      ),
                      Visibility(
                        visible: entity.ifCardModel == 1,
                        child: Container(
                          margin: EdgeInsets.only(left: 8.w),
                          padding: EdgeInsets.only(left: 5.w, right: 5.w, bottom: 1.w),
                          decoration: BoxDecoration(
                            color: Colours.color_white,
                            borderRadius: BorderRadius.circular(5.w),
                            border: Border.all(width: 1.w, color: Colours.color_6f7082),
                          ),
                          child: Text(
                            "卡账户",
                            style: TextStyle(
                              color: Colours.color_6f7082,
                              fontSize: 10.sp,
                            ),
                          ),
                        ),
                      ),
                      Visibility(
                        visible: entity.status == 0,
                        child: Container(
                          margin: EdgeInsets.only(left: 8.w),
                          padding: EdgeInsets.only(left: 5.w, right: 5.w, bottom: 1.w),
                          decoration: BoxDecoration(
                            color: Colours.color_cfcfd5,
                            borderRadius: BorderRadius.circular(5.w),
                            border: Border.all(width: 1.w, color: Colours.color_cfcfd5),
                          ),
                          child: Text(
                            "已禁用",
                            style: TextStyle(
                              color: Colours.color_white,
                              fontSize: 10.sp,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 5.w,
                  ),
                  Row(
                    children: [
                      Image.asset(
                        "images/ic_phone.png",
                        height: 14.w,
                        width: 14.w,
                        color: Colours.color_6f7082,
                      ),
                      SizedBox(
                        width: 5.w,
                      ),
                      HighlightRichText(
                        text: entity.phone ?? "",
                        highlightList: [keyword ?? ""],
                        highlightStyle: TextStyle(
                          color: Colours.color_theme,
                          fontSize: 14.sp,
                        ),
                        normalStyle: TextStyle(
                          color: Colours.color_6f7082,
                          fontSize: 14.sp,
                        ),
                      ),
                      Text(
                        "  l  ",
                        style: TextStyle(color: Colours.color_e7e7ea, fontSize: 12.sp),
                      ),
                      Flexible(
                        child: TextWithIcon(
                          text: (entity.motorcadeName ?? "").isNotEmpty ? (entity.motorcadeName ?? "") : "无归属车队",
                          iconName: "images/ic_motorcade.png",
                          iconHeight: 14.w,
                          iconWidth: 14.w,
                          iconColor: Colours.color_6f7082,
                          textStyle: TextStyle(color: Colours.color_6f7082, fontSize: 12.sp),
                          textIconPadding: 5.w,
                        ),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: (entity.subCompanyList ?? []).isNotEmpty ? 5.w : 0,
                  ),
                  FlexibleIconText(
                    icon: Image.asset(
                      "images/ic_company.png",
                      height: 14.w,
                      width: 14.w,
                      color: Colours.color_6f7082,
                    ),
                    textList: entity.subCompanyList,
                    iconTextPadding: 5.w,
                  ),
                  SizedBox(
                    height: quotaList.isNotEmpty ? 5.w : 0,
                  ),
                  FlexibleIconText(
                    textList: quotaList,
                    textStyle: TextStyle(color: Colours.color_text_theme, fontSize: 12.sp),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
